home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Mac / Python / macshlglue.c < prev   
Encoding:
C/C++ Source or Header  |  1996-08-21  |  1.7 KB  |  67 lines  |  [TEXT/CWIE]

  1. /*
  2. ** Shared library initialization code.
  3. **
  4. ** This code calls the MetroWerks shared-library initialization code
  5. ** and performs one extra step: it remembers the FSSpec of the file
  6. ** we are loaded from, so we can later call PyMac_AddLibResources to
  7. ** add the file to our resource file chain.
  8. **
  9. ** This file is needed for PythonCore and for any dynamically loaded
  10. ** module that has interesting resources in its .slb file.
  11. ** Use by replacing __initialize in the "CFM preferences" init field
  12. ** by __initialize_with_resources.
  13. */
  14.  
  15. #include <Quickdraw.h>
  16. #include <SegLoad.h>
  17. #include <FragLoad.h>
  18. #include <Files.h>
  19. #include <Resources.h>
  20.  
  21.  
  22. /*
  23. ** Variables passed from shared lib initialization to PyMac_AddLibResources.
  24. */
  25. static int library_fss_valid;
  26. static FSSpec library_fss;
  27.  
  28. /*
  29. ** Routine called upon fragment load. We attempt to save the FSSpec from which we're
  30. ** loaded. We always return noErr (we just continue without the resources).
  31. */
  32. OSErr pascal
  33. __initialize_with_resources(InitBlockPtr data)
  34. {
  35.     /* Call the MW runtime's initialization routine */
  36. /* #ifdef __CFM68K__ */
  37. #if 1
  38.     __initialize();
  39. #else
  40.     __sinit();
  41. #endif
  42.     
  43.     if ( data == nil ) return noErr;
  44.     if ( data->fragLocator.where == kOnDiskFlat ) {
  45.         library_fss = *data->fragLocator.u.onDisk.fileSpec;
  46.         library_fss_valid = 1;
  47.     } else if ( data->fragLocator.where == kOnDiskSegmented ) {
  48.         library_fss = *data->fragLocator.u.inSegs.fileSpec;
  49.         library_fss_valid = 1;
  50.     }
  51.     return noErr;
  52. }
  53.  
  54. /*
  55. ** Insert the library resources into the search path. Put them after
  56. ** the resources from the application (which we assume is the current
  57. ** resource file). Again, we ignore errors.
  58. */
  59. void
  60. PyMac_AddLibResources()
  61. {
  62.     if ( !library_fss_valid ) 
  63.         return;
  64.     (void)FSpOpenResFile(&library_fss, fsRdPerm);
  65. }
  66.  
  67.